package three;

import java.util.Scanner;

public class test11077 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        String s2 = scanner.next();
        char[] str1 = s1.toCharArray();
        char[] str2 = s2.toCharArray();
        int m = str1.length;
        int n = str2.length;
        int[][] max = new int[m][n];
        /*
        定义f(m,n)：   分别以str1[m],str2[n]结尾的最长连续公共子串的长度，
               其中字符串末尾的str1[m]和str2[n]包含在最长公共子串中，即为最长公共子串的最末元素。
         */
        q(str1, str2, m, n, max);
        int maxlen = 0;
        int endindex = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (maxlen < max[i][j]) {
                    maxlen = max[i][j];
                    endindex = i;
                }
            }
        }
        System.out.println(maxlen);
        for (int i = endindex - maxlen + 1; i <= endindex; i++) {
            System.out.print(str1[i]);
        }
    }

    private static void q(char[] s1, char[] s2, int m, int n, int[][] max) {
        for (int i = 0; i < m; i++) {
            if (s1[i] == s2[0]) {
                max[i][0] = 1;
            } else {
                max[i][0] = 0;
            }
        }
        for (int j = 0; j < n; j++) {
            if (s1[0] == s2[j]) {
                max[0][j] = 1;
            } else {
                max[0][j] = 0;
            }
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (s1[i] != s2[j]) {
                    max[i][j] = 0;
                } else {
                    max[i][j] = max[i - 1][j - 1] + 1;
                }
            }
        }
    }
}
